import { GET, POST } from './ajax';

// 注册获取验证码
export const sendCode = (phone) => GET(`sms/sendCode/${phone}/1`);

// 注册
export const register = (user) => POST('user/register', user);

// 用户名密码登录
export const login = (user) => POST('user/login', user);

// 登录请求短信
export const loginSendCode = (phone) => GET(`sms/sendCode/${phone}/2`);

// 短信登录
export const smsLogin = (data) => POST('sms/smsLogin', data);

// 判断用户是否登录
export const isLogin = () => GET('user/isLogin/');

// 退出登录
export const logout = () => GET('user/logout');

// 开通会员
export const openVip = (data) => POST('pay/alipay', data)

// 获取树形分类数据
export const listCategoryWithTree = () => GET('category/treeCategory')

// 获取min所有分类数据
export const listMinCategory = (parentId) => GET(`category/getMinCategory/${parentId}`)

// 修改min分类复选框选中事件
export const updateMinCategoryChecked = (id, checked) => GET(`category/updateMinCategoryChecked/${id}/${checked}`)

// 上传文件请求
export const uploadFile = (formData) => POST('files/uploadFile', formData, {
  headers: { 'Content-Type': 'multipart/form-data' }
})

// 提交创建文件夹请求
export const createFolder = (data) => POST('folders/createFolder', data)

// 请求当前parentId所有文件夹以及文件
export const fetchAllFileByParentId = (parentId) => GET(`files/listFolderAndFile/${parentId}`)

// 根据分类id请求文件
export const fetchFileByCategoryId = (categoryId) => GET(`files/listFileByCategoryId/${categoryId}`)

// 根据文件夹id获取文件夹
export const getFolderById = (id) => GET(`folders/getFolder/${id}`)

// 本地分片预上传
export const preChunkUploadLocal = (data) => POST('files/preChunkUploadLocal', data)

// 本地分片上传
export const partUploadLocal = (formData) => POST('files/partUploadLocal', formData, {
  headers: { 'Content-Type': 'multipart/form-data' }
})

// 取消正在上传至本地的文件
export const cancelLocalUploading = (data) => POST('files/cancelLocalUploading', data)

// 本地分片预上传
export const preChunkUploadFastDFS = (data) => POST('files/preChunkUploadFastDFS', data)

// 本地分片上传
export const partUploadFastDFS = (formData) => POST('files/partUploadFastDFS', formData, {
  headers: { 'Content-Type': 'multipart/form-data' }
})

// 取消正在上传至本地的文件
export const cancelFastDFSUploading = (data) => POST('files/cancelFastDFSUploading', data)

// 删除文件
export const deleteFiles = (data) => POST('files/deleteFiles', data)

// 删除目录
export const deleteFolders = (data) => POST('folders/deleteFolders', data)

// 重命名文件
export const renameFile = (id, name) => GET(`files/renameFile/${id}/${name}`)

export const renameFolder = (id, name) => GET(`folders/renameFolder/${id}/${name}`)


